using System;
using System.Data;
using System.Diagnostics;
using System.Configuration;
using System.Collections;
using System.Text;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

namespace WebClient
{
    public partial class Skin : System.Web.UI.MasterPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if(!Page.IsPostBack)
            {
                string[] forms = null;
                UIProcessSchemaObjects.DownloadFormRequest formDownloadRequest = null;
                UIProcessSchemaObjects.Form form = null;

                UIProcessServiceClient serviceProxy = new UIProcessServiceClient();
                UIProcessSchemaObjects.DownloadFormListRequest formListRequest = new UIProcessSchemaObjects.DownloadFormListRequest();
                try
                {
                    forms = serviceProxy.DownloadFormList(formListRequest);
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.Message);
                    Debug.WriteLine(ex.Source);
                    Debug.WriteLine(ex.StackTrace);
                }

                if (forms != null)
                {
                    StringBuilder menu = new StringBuilder();
                    foreach (string formName in forms)
                    {
                        try
                        {
                            formDownloadRequest = new UIProcessSchemaObjects.DownloadFormRequest();
                            formDownloadRequest.FormName = formName;

                            form = serviceProxy.DownloadForm(formDownloadRequest);
                        }
                        catch(Exception ex)
                        {
                            Debug.WriteLine(ex.Message);
                            Debug.WriteLine(ex.Source);
                            Debug.WriteLine(ex.StackTrace);
                        }

                        if(form != null)
                        {
                            menu.Append("&nbsp;&nbsp;&nbsp;<a href=\"Default.aspx?Form=");
                            menu.Append(formName);
                            menu.Append("\">");
                            menu.Append(form.Name);
                            menu.Append("</a><br />");
                        }
                    }
                    menuLinks.Text = menu.ToString();
                }
            }
        }
    }
}
